<?
require("config.php");

$label = "Product List";

$table="pro_basic";

if ($currency==NULL) $currency = "usd";

$currency = "price_" . $currency;

if ($action=="search"){


	$Query="SELECT 
	id,
	code,
	name,
	brand,
	category,
	$currency 

	FROM $table WHERE 

	code		LIKE '%$Code%'		AND 
	name		LIKE '%$Name%'		AND
	brand		LIKE '%$Brand%'		AND
	type		LIKE '%$Type%'		AND
	category	LIKE '%$Category%' 
	ORDER BY id DESC";

	$r=myQuery($Query);

}else{

	$Query="SELECT 
	id,
	code,
	name,
	brand,
	category,
	$currency 
	FROM $table ORDER BY brand, code";

	$r=myQuery($Query);

}

$Query = "select code, name from pro_brand";
$brands = myQuery($Query);

$Query = "select code, name from pro_type";
$types = myQuery($Query);


$Query = "select code, name from pro_category";
$categorys = myQuery($Query);


require($rela_path . "inc/header1.php");
?>
      <br>




      <table width="90%" border="0" align="center">
        <tr> 
          <td>
		  
		  
		  
		  
		  
<FORM METHOD=get ACTION="">		  
		  
<input name="action" type="hidden" value="search">
		  
		  <table border="0">
              <tr> 
                <td><strong>Search by </strong></td>
                <td>&nbsp;</td>
              </tr>
              <tr> 
                <td>Product Code :</td>
                <td><input type="text" class="text" name="Code"></td>
              </tr>
              <tr> 
                <td>Product Name :</td>
                <td><input type="text" class="text" name="Name"></td>
              </tr>
              <tr> 
                <td>Brand :</td>
                <td>
<select class="select" name="Brand"  <?print($active)?>>
<option value="" selected>----------------------</option>
<?
for ($i=0;$i<count($brands);$i++){
	print("<option value=" . $brands[$i][0] . ">" . $brands[$i][1] . "</option>");
}

?>
</select> 
				  
				  </td>
              </tr>
              <tr> 
                <td>Type :</td>
                <td>
<select class="select" name="Type"  <?print($active)?>>
<option value="" selected>----------------------</option>
<?
for ($i=0;$i<count($types);$i++){
	print("<option value=" . $types[$i][0] . ">" . $types[$i][1] . "</option>");
}

?>
</select> 
				  
				  </td>
              </tr>
              <tr> 
                <td>Category :</td>
                <td>
<select class="select" name="Category"  <?print($active)?>>
<option value="" selected>----------------------</option>
<?
for ($i=0;$i<count($categorys);$i++){
	print("<option value=" . $categorys[$i][0] . ">" . $categorys[$i][1] . "</option>");
}

?>
</select> 
				  
				  </td>
              </tr>
              <tr> 
                <td>&nbsp;</td>
                <td><input type="submit" class="button" name="Submit2" value="  Go  "></td>
              </tr>
            </table>
			
	</FORM>		
			
			</td>
        </tr>
      </table>
      <br>







<script language="javascript">
function fillForm(ProductCode,ProductName,ProductPrice){
opener.form2.ProductCode.value=ProductCode;
opener.form2.ProductName.value=ProductName;
opener.form2.Price.value=ProductPrice;
//opener.form2.Qty.value=1;
top.close();
}
</script>
      
<table width="90%" border="0" align="center" cellpadding="1" cellspacing="1" class="tb">
  <tr class="tbheader"> 
    <td width="2%"> <div align="center">No.</div></td>
    <td width="10%"> <div align="center">Product Code</div></td>
    <td width="41%"> <div align="center">Product Name</div></td>
    <td width="13%"> <div align="center">Brand</div></td>
    <td width="12%"> <div align="center">Category</div></td>
    <td width="10%"> <div align="center">&nbsp;</div></td>
  </tr>

<?if ($r){
	for ($i=0;$i<count($r);$i++){?>
  <tr class="tbcontent1"> 
    <td width="2%" align="right"><?print($i+1)?></td>
    <td width="10%">

	<?if ($fillform){?>
	<a href="javascript:fillForm(<?print("'" . $r[$i][1] . "','" . $r[$i][2] . "','" . $r[$i][5] . "'")?>)">
	<?print($r[$i][1])?></a>
	<?}else{?>
	<?print($r[$i][1])?>
	<?}?>


	
	</td>
    <td width="41%"><?print($r[$i][2])?></td>
    <td width="13%"> <div align="center"><?print($r[$i][3])?></div></td>
    <td width="12%"> <div align="center"><?print($r[$i][4])?></div></td>
    <td width="10%"> <div align="center"><a href="product_list_detail.php?id=<?print($r[$i][0])?>">Detail</a></div></td>
  </tr>
<?}
}?>


</table>

      <p>&nbsp;</p>
      <p>&nbsp;</p>
<?
require($rela_path . "inc/footer1.php");
?>
